home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Initialize.c
-
- Contains: Sample code for Language Analysis Manager.
-
- Version: Technology: System 8
- Release: Daruma Developer Release 1
-
- Copyright: 1998 by Apple Computer, Inc., all rights reserved
-
- Contact: daruma@apple.com
-
- */
-
-
- #include "TestApp.h"
- #include "FunctionProto.h"
-
- #include <Fonts.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <TextUtils.h>
- #include <Windows.h>
-
-
- // ========================================================================================
- // Prototypes for static functions
- // ========================================================================================
- static OSStatus SetUpMenus ( void );
- static OSStatus CreateInputDialog ( void );
- static void SetUpDefaultStatus ( void );
-
-
- // ========================================================================================
- // Initialize
- // ========================================================================================
- OSStatus Initialize ( void )
- {
- OSStatus err;
- Rect consoleRect;
- WindowResHandle windRes;
-
- //------------------------------------------------------------------------------
- // Initialize Toolbox
- //
- InitGraf( (Ptr)&qd.thePort);
- InitFonts();
- FlushEvents( everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil);
- InitCursor();
-
- gAnalysisMode = 0;
-
- //------------------------------------------------------------------------------
- // Create menu
- //
- err = SetUpMenus();
- nrequire( err, setupMenu_Failure);
-
- //------------------------------------------------------------------------------
- // Create console window
- //
- windRes = (WindowResHandle)Get1Resource( 'WIND', kConsoleWindowResID);
- require( windRes, getConsoleRes_Failure);
-
- HLock( (Handle)windRes);
-
- consoleRect = (**windRes).windRect;
- consoleRect.bottom = qd.screenBits.bounds.bottom - 10;
- err = NewConsoleWindow( &consoleRect, (**windRes).title, (**windRes).visible,
- (**windRes).procID, (WindowRef)-1L, (**windRes).goAway,
- (**windRes).refcon, "\pOsaka", 12, &gConsoleWindow);
-
- HUnlock( (Handle)windRes);
- ReleaseResource( (Handle)windRes);
- nrequire( err, createConsole_Failure);
-
- //------------------------------------------------------------------------------
- // Create input window
- //
- err = CreateInputDialog();
- nrequire( err, createDialog_Failure);
-
- SetUpDefaultStatus();
-
- return noErr;
-
- //`````````````````````````````````````````````````````````````````````````````
- // Error handling
- //
- createDialog_Failure:
- DisposeConsoleWindow( gConsoleWindow);
- gConsoleWindow = NULL;
- createConsole_Failure:
- getConsoleRes_Failure:
- setupMenu_Failure:
- return err;
- }
-
-
- // ========================================================================================
- // SetUpMenus
- // ========================================================================================
- static OSStatus SetUpMenus ( void )
- {
- OSStatus err;
- Handle menuBar;
- MenuRef fontMenu, sizeMenu, levelMenu;
-
- menuBar = GetNewMBar( kMenuBarResID);
- require_action( menuBar, getMenuBar_Failure, err = ResError(););
-
- SetMenuBar( menuBar);
-
- fontMenu = GetMenu( kFontMenuID);
- InsertMenu( fontMenu, hierMenu);
-
- sizeMenu = GetMenu( kSizeMenuID);
- InsertMenu( sizeMenu, hierMenu);
-
- AppendResMenu( GetMenuHandle( kAppleMenuID), 'DRVR');
- AppendResMenu( GetMenuHandle( kFontMenuID), 'FONT');
-
- levelMenu = GetMenu( kLevelMenuID);
- InsertMenu( levelMenu, hierMenu);
-
- DrawMenuBar();
-
- return noErr;
-
- //`````````````````````````````````````````````````````````````````````````````
- // Error handling
- //
- getMenuBar_Failure:
- return err;
- }
-
-
- // ========================================================================================
- // CreateInputDialog
- // ========================================================================================
- static OSStatus CreateInputDialog ( void )
- {
- OSStatus err;
- DialogRef dialog;
- InputDialogPtr infoDialogPtr;
- ControlRef control;
-
- //------------------------------------------------------------------------------
- // Pre-load env menu because the menu which loaded at creating popup menu
- // is disposed on DisposeDialog. This can be a problem with multi window application.
- //
- {
- MenuRef envMenu;
-
- envMenu = GetMenu( kEnvironmentMenuID);
- InsertMenu( envMenu, hierMenu);
- }
-
- dialog = GetNewDialog( kInputDialogResID, NULL, (WindowRef)-1L);
- require_action( dialog, getDialog_Failure, err = ResError(););
-
- infoDialogPtr = (InputDialogPtr)NewPtrClear( sizeof( InputDialogRec));
- require_action( infoDialogPtr, allocDialogInfo_Failure, err = memFullErr;);
-
- infoDialogPtr->dialog = dialog;
- infoDialogPtr->analysisBundle.descriptorType = typeNull;
- infoDialogPtr->analysisPath.descriptorType = typeNull;
-
- SetWRefCon( (WindowRef)dialog, (long)infoDialogPtr);
- SetDialogDefaultItem( dialog, kConvertBtnDItemID);
-
- gInputDialog = infoDialogPtr;
-
- //------------------------------------------------------------------------------
- // Create environment menu
- //
- err = SetUpAllAnalysisEnvironment( infoDialogPtr);
- nrequire( err, setupEnvMenu_Failure);
-
- //------------------------------------------------------------------------------
- // Set default environment
- //
- control = (ControlRef)GetDialogItemHandle( dialog, kEnvironPopupDItemID);
- SetControlValue( control, kKanaKanjiMenuItemID);
-
- err = SetAnalysisEnvironment( infoDialogPtr);
- nrequire( err, setDarumaEnv_Failure);
-
- ChangeAnalysisMethod( kBatchAnalysisMode);
-
- ShowWindow( (WindowRef)dialog);
-
- return noErr;
-
- //`````````````````````````````````````````````````````````````````````````````
- // Error handling
- //
- setDarumaEnv_Failure:
- setupEnvMenu_Failure:
- DisposePtr( (Ptr)infoDialogPtr);
- allocDialogInfo_Failure:
- DisposeDialog( dialog);
- getDialog_Failure:
- gInputDialog = NULL;
- return err;
- }
-
-
- // ========================================================================================
- // SetUpDefaultStatus
- // ========================================================================================
- static void SetUpDefaultStatus ( void )
- {
- short menuCount, i;
- Str255 itemName;
- MenuRef fontMenu, sizeMenu;
-
- //------------------------------------------------------------------------------
- // Set default console font to Osaka-Mono
- //
- fontMenu = GetMenuHandle( kFontMenuID);
- menuCount = CountMItems( fontMenu);
-
- for ( i = 1; i <= menuCount; ++i)
- {
- GetMenuItemText( fontMenu, i, itemName);
- if ( EqualString( itemName, "\pOsakaÅ|ìôïù", false, true))
- {
- CheckItem( fontMenu, i, true);
- SetConcoleWindowFont( gConsoleWindow, "\pOsakaÅ|ìôïù", false);
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // If Osaka-Mono can't be found, use Osaka
- //
- if ( i > menuCount)
- {
- for ( i = 1; i <= menuCount; ++i)
- {
- GetMenuItemText( fontMenu, i, itemName);
- if ( EqualString( itemName, "\pOsaka", false, true))
- {
- CheckItem( fontMenu, i, true);
- SetConcoleWindowFont( gConsoleWindow, "\pOsaka", false);
- break;
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Set default console font size to 12
- //
- sizeMenu = GetMenuHandle( kSizeMenuID);
- menuCount = CountMItems( sizeMenu);
-
- for ( i = 1; i <= menuCount; ++i)
- {
- GetMenuItemText( sizeMenu, i, itemName);
- if ( EqualString( itemName, "\p12", false, true))
- {
- CheckItem( sizeMenu, i, true);
- break;
- }
- }
- }
-
-
-
-